<template>
  <div class="login-page">
    <el-card class="el-card">
      <template #header>面经运营后台</template>
      <el-form   ref="form"  :model="form" :rules="rules">
        <el-form-item label="用户名：" prop="username">
          <el-input v-model="form.username" placeholder="请输入用户名" />
        </el-form-item>
        <el-form-item label="密码："  prop="password">
          <el-input   type="password"  v-model="form.password" placeholder="请输入密码：" />
        </el-form-item>
        <el-form-item>
          <el-button    @click="login"  type="primary">登录</el-button>
          <el-button  @click="resetForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
  
  <script>


// import  { login }  from  '@/api/user'

export default {
  name: "LoginIndex",
  data() {
    return {
      form: {
        username: "admin",
        password: "123456",
      
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 15 个字符", trigger: "blur" },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          { min: 3, max: 15, message: "长度在 3 到 15 个字符", trigger: "blur" },
        ],
      },
    };
  },
  methods:{

    // login:  function(){},
   async login(){
    try {
       await this.$refs.form.validate()
      // 测试账号密码  admin      123456
      // const  res = await login(this.form)
      // console.log(res)

      // console.log(this.$store.state.user.a)
      // console.log(this.$store.commit('user/setA',300))

        this.$store.dispatch(
        'user/loginAction',
        this.form
        )



    } catch (e) {
      console.log(e)
    }
    },
    resetForm(){
      this.$refs.form.resetFields()
    }
  }
};
</script>
  

  <style lang="scss" scoped>
.login-page {
  min-height: 100vh;
  background: url(@/assets/login-bg.svg) no-repeat center / cover;
  display: flex;
  align-items: center;
  justify-content: center;
  .el-card {
    width: 420px;

    ::v-deep .el-card__header {
      height: 80px;
      line-height: 40px;
      background: rgba(114, 124, 245, 1);
      text-align: center;
      color: #fff;
      font-size: 18px;
    }
  }
  .el-form {
    padding: 0 20px;
  }
  .tc {
    text-align: center;
  }
}
</style>